package com.ylxn.mapper;

import com.ylxn.pojo.User;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.redis.RedisCache;

import javax.persistence.Table;
import java.util.List;

/**
 * redis缓存实现
 */
@Table(name = "user")
public interface IUserMapper {

    public List<User> findAll();

    public List<User> findAllUserAndRole();

    @Insert("insert into user(id,username) values(#{id},#{username})")
    public void addUser(User user);

    @Update("update user set username = #{username} where id = #{id}")
    public Integer updateUser(User user);

    @Select("select * from user")
    public List<User> selectUsers();

    @Delete("delete from user where id = #{id}")
    public Integer deleteUser(Integer id);

    @Select("select * from user where id = #{id}")
    public User findUserById(Integer id);

    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "orders",column = "id",javaType = List.class,many = @Many(select = "com.ylxn.mapper.IOrderMapper.findOrderById")),
    })
    @Select("select * from user")
    public List<User> findAllUser();

    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "roles",column = "id",javaType = List.class,many = @Many(select = "com.ylxn.mapper.IRoleMapper.findAllRoleById"))
    })
    @Select("select * from user")
    public List<User> findAllUserAndRoleBy();
}
